import {createApp} from 'vue'
import './style.css'
import App from './App.vue'
import {createRouter, createWebHistory} from 'vue-router';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';

import Login from "./views/Login.vue";
import Home from "./views/Home.vue";
import My from "./views/My.vue";
import FAQ from "./views/FAQ.vue";
import FAQhistory from "./views/FAQhistory.vue";

const routes = [
    {
        path: '/login',
        name: 'login',
        component: Login,
    },
    {
        path: '/',
        name: 'home',
        component: Home,
        children: [
            {path: 'my', name: 'my', component: My},
            {path: 'faq', name: 'faq', component: FAQ},
            {path: 'faq-history', name: 'faqHistory', component: FAQhistory},
        ]
    }
]
const router = createRouter({
    history: createWebHistory(),
    routes,
});
router.beforeEach((to, from, next) => {
    if (!localStorage.getItem('token') && !['login'].includes(to.name)) {
        next({name: 'login'});
        return;
    }
    next();
})
createApp(App).use(router).use(Antd).mount('#app')
